// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  let db = cloud.database()
  const _ = db.command
  let newEvaluate = {
    evaluate:event.evaluate,
    score:event.score,
    image:event.image,
    name:event.name,
    openid:wxContext.OPENID,
  }
  //增加新评论
  db.collection('evaluate').doc(event.id).update({
      data: {
        evaluate: _.push(newEvaluate)
      }
    })
    .then(e => {
      console.log('更新成功', e)
    })
    .catch(err => {
      console.log("更新失败", err)
    })
}